from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-07 14:14:28.711717
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 07, Jan, 2021
Time: 14:14:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -44.7690
Nobs: 164.000 HQIC: -45.7796
Log likelihood: 1806.20 FPE: 6.58960e-21
AIC: -46.4702 Det(Omega_mle): 3.86821e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.453826 0.155218 2.924 0.003
L1.Burgenland 0.136669 0.078768 1.735 0.083
L1.Kärnten -0.240943 0.064032 -3.763 0.000
L1.Niederösterreich 0.120721 0.183277 0.659 0.510
L1.Oberösterreich 0.243089 0.157117 1.547 0.122
L1.Salzburg 0.186860 0.082784 2.257 0.024
L1.Steiermark 0.078486 0.113252 0.693 0.488
L1.Tirol 0.143804 0.075324 1.909 0.056
L1.Vorarlberg 0.012442 0.071882 0.173 0.863
L1.Wien -0.118320 0.152363 -0.777 0.437
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.524322 0.199561 2.627 0.009
L1.Burgenland 0.009715 0.101271 0.096 0.924
L1.Kärnten 0.370357 0.082324 4.499 0.000
L1.Niederösterreich 0.135087 0.235636 0.573 0.566
L1.Oberösterreich -0.172612 0.202002 -0.855 0.393
L1.Salzburg 0.180007 0.106434 1.691 0.091
L1.Steiermark 0.241057 0.145606 1.656 0.098
L1.Tirol 0.139841 0.096843 1.444 0.149
L1.Vorarlberg 0.183055 0.092417 1.981 0.048
L1.Wien -0.595485 0.195891 -3.040 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.294416 0.068008 4.329 0.000
L1.Burgenland 0.103336 0.034512 2.994 0.003
L1.Kärnten -0.027251 0.028055 -0.971 0.331
L1.Niederösterreich 0.067430 0.080302 0.840 0.401
L1.Oberösterreich 0.291263 0.068840 4.231 0.000
L1.Salzburg 0.000188 0.036271 0.005 0.996
L1.Steiermark -0.021818 0.049621 -0.440 0.660
L1.Tirol 0.089975 0.033003 2.726 0.006
L1.Vorarlberg 0.127260 0.031495 4.041 0.000
L1.Wien 0.081461 0.066757 1.220 0.222
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198183 0.079017 2.508 0.012
L1.Burgenland -0.010739 0.040098 -0.268 0.789
L1.Kärnten 0.022530 0.032596 0.691 0.489
L1.Niederösterreich 0.036735 0.093301 0.394 0.694
L1.Oberösterreich 0.405524 0.079983 5.070 0.000
L1.Salzburg 0.095000 0.042143 2.254 0.024
L1.Steiermark 0.180723 0.057653 3.135 0.002
L1.Tirol 0.034774 0.038345 0.907 0.364
L1.Vorarlberg 0.101817 0.036593 2.782 0.005
L1.Wien -0.066699 0.077563 -0.860 0.390
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.574358 0.161561 3.555 0.000
L1.Burgenland 0.074590 0.081987 0.910 0.363
L1.Kärnten 0.001809 0.066648 0.027 0.978
L1.Niederösterreich -0.011458 0.190767 -0.060 0.952
L1.Oberösterreich 0.143917 0.163538 0.880 0.379
L1.Salzburg 0.047918 0.086167 0.556 0.578
L1.Steiermark 0.105650 0.117880 0.896 0.370
L1.Tirol 0.215997 0.078402 2.755 0.006
L1.Vorarlberg 0.011833 0.074819 0.158 0.874
L1.Wien -0.147964 0.158590 -0.933 0.351
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153569 0.114417 1.342 0.180
L1.Burgenland -0.025756 0.058063 -0.444 0.657
L1.Kärnten -0.011593 0.047200 -0.246 0.806
L1.Niederösterreich 0.192507 0.135100 1.425 0.154
L1.Oberösterreich 0.386594 0.115817 3.338 0.001
L1.Salzburg -0.031963 0.061023 -0.524 0.600
L1.Steiermark -0.048610 0.083482 -0.582 0.560
L1.Tirol 0.191809 0.055524 3.455 0.001
L1.Vorarlberg 0.047696 0.052987 0.900 0.368
L1.Wien 0.153054 0.112313 1.363 0.173
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.238692 0.143925 1.658 0.097
L1.Burgenland 0.060487 0.073037 0.828 0.408
L1.Kärnten -0.050424 0.059373 -0.849 0.396
L1.Niederösterreich -0.033441 0.169943 -0.197 0.844
L1.Oberösterreich -0.101318 0.145686 -0.695 0.487
L1.Salzburg 0.019026 0.076761 0.248 0.804
L1.Steiermark 0.375408 0.105012 3.575 0.000
L1.Tirol 0.515099 0.069844 7.375 0.000
L1.Vorarlberg 0.192905 0.066652 2.894 0.004
L1.Wien -0.213149 0.141278 -1.509 0.131
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118340 0.168836 0.701 0.483
L1.Burgenland 0.011683 0.085679 0.136 0.892
L1.Kärnten -0.109146 0.069649 -1.567 0.117
L1.Niederösterreich 0.215980 0.199357 1.083 0.279
L1.Oberösterreich 0.009104 0.170901 0.053 0.958
L1.Salzburg 0.220603 0.090047 2.450 0.014
L1.Steiermark 0.145660 0.123188 1.182 0.237
L1.Tirol 0.091799 0.081932 1.120 0.263
L1.Vorarlberg 0.017429 0.078188 0.223 0.824
L1.Wien 0.288487 0.165731 1.741 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.585108 0.092055 6.356 0.000
L1.Burgenland -0.020805 0.046715 -0.445 0.656
L1.Kärnten -0.000651 0.037975 -0.017 0.986
L1.Niederösterreich -0.007753 0.108696 -0.071 0.943
L1.Oberösterreich 0.280707 0.093181 3.012 0.003
L1.Salzburg 0.010482 0.049097 0.213 0.831
L1.Steiermark -0.001039 0.067166 -0.015 0.988
L1.Tirol 0.077523 0.044672 1.735 0.083
L1.Vorarlberg 0.171124 0.042631 4.014 0.000
L1.Wien -0.090218 0.090362 -0.998 0.318
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.146635 -0.001562 0.207009 0.244655 0.065669 0.097621 -0.077370 0.161490
Kärnten 0.146635 1.000000 -0.007205 0.186564 0.151424 -0.138633 0.163484 0.027658 0.304478
Niederösterreich -0.001562 -0.007205 1.000000 0.259455 0.079322 0.205768 0.104858 0.055608 0.349235
Oberösterreich 0.207009 0.186564 0.259455 1.000000 0.290345 0.301403 0.099926 0.075672 0.113639
Salzburg 0.244655 0.151424 0.079322 0.290345 1.000000 0.151944 0.076470 0.077272 -0.021578
Steiermark 0.065669 -0.138633 0.205768 0.301403 0.151944 1.000000 0.101864 0.091620 -0.126527
Tirol 0.097621 0.163484 0.104858 0.099926 0.076470 0.101864 1.000000 0.148931 0.140002
Vorarlberg -0.077370 0.027658 0.055608 0.075672 0.077272 0.091620 0.148931 1.000000 0.099763
Wien 0.161490 0.304478 0.349235 0.113639 -0.021578 -0.126527 0.140002 0.099763 1.000000